﻿namespace ExamV5.LineStudyExam
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmJoinExamParm : Page
    {
        protected HtmlInputHidden EndTime;
        protected HtmlForm Form1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private HttpCookie httpCookie_4 = null;
        protected Image ImageUser;
        protected int intPaperID = 0;
        protected Label labDeptName;
        protected Label labExamName;
        protected Label labExamTime;
        protected Label labPaperFen;
        protected Label labUserCode;
        protected Label labUserName;
        private PublicFun publicFun_0 = new PublicFun();
        protected HtmlInputHidden StartTime;
        protected string strEndTime = null;
        protected string strLoadInfo = "0";
        protected string strStartTime = null;
        protected string strSumTime = null;
        protected HtmlInputHidden SumTime;
        protected HtmlInputHidden txtHideComm;
        protected HtmlInputHidden txtHideEnter;

        private void method_0()
        {
            string strSql = "";
            string str2 = Convert.ToString(base.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
            if (!(!(str2 == "") ? (str2 != null) : false))
            {
                str2 = Convert.ToString(base.Request.ServerVariables["REMOTE_ADDR"]);
            }
            this.strEndTime = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" + DateTime.Now.Second.ToString();
            TimeSpan span = (TimeSpan) (DateTime.Now - Convert.ToDateTime(this.ViewState["JoinExamStartTime"].ToString()));
            if (!(this.ViewState["ExamType"].ToString() == "C"))
            {
                strSql = string.Concat(new object[] { "update ExamUser set LastTime=LastTime-", span.TotalMinutes.ToString(), ",LastDate='", DateTime.Now.ToShortDateString(), "',LoginIP='", str2, "',EndTime='", this.strEndTime, "' where UserCode='", this.httpCookie_0.Value.Trim(), "' and PaperID=", this.intPaperID });
                this.ViewState["JoinExamStartTime"] = DateTime.Now.ToString();
            }
            else
            {
                strSql = string.Concat(new object[] { "update ExamUser set LastTime='", this.labExamTime.Text, "',LastDate='", DateTime.Now.ToShortDateString(), "',LoginIP='", str2, "',EndTime='", this.strEndTime, "' where UserCode='", this.httpCookie_0.Value.Trim(), "' and PaperID=", this.intPaperID });
            }
            this.publicFun_0.ExecuteSql(strSql);
        }

        private void method_1()
        {
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(string.Concat(new object[] { "select a.EnterTime,a.PaperEndTime,a.PaperStatus,a.ExamName,a.SubjectName,a.PaperFen,a.ExamTime,b.LastTime from PaperInfo a,ExamUser b where b.UserCode='", this.httpCookie_0.Value, "' and b.PaperID=a.ID and a.ID=", this.intPaperID }), connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            if (!reader.Read())
            {
                base.Response.Write("<script>alert('没有找到相关试卷参数！');</script>");
            }
            else
            {
                this.ViewState["ExamType"] = reader["PaperStatus"].ToString();
                this.labExamName.Text = reader["ExamName"].ToString();
                this.labPaperFen.Text = reader["PaperFen"].ToString();
                this.labExamTime.Text = reader["ExamTime"].ToString();
                this.Page.Title = reader["ExamName"].ToString();
                if (this.labExamName.Text.Trim().Length > 0x12)
                {
                    this.labExamName.Text = this.labExamName.Text.Substring(0, 0x12) + "…";
                }
                int num = 0;
                if (!(reader["EnterTime"].ToString().Trim() == "A"))
                {
                    TimeSpan span = (TimeSpan) (Convert.ToDateTime(reader["PaperEndTime"].ToString()) - DateTime.Now);
                    num = Convert.ToInt32(span.TotalMinutes);
                }
                else
                {
                    num = Convert.ToInt32(reader["LastTime"].ToString().Trim());
                }
                if (num <= 0)
                {
                    num = 1;
                }
                this.SumTime.Value = num.ToString();
                this.ViewState["PaperSumTime"] = this.SumTime.Value;
                this.StartTime.Value = DateTime.Now.ToLongTimeString();
                this.strStartTime = this.StartTime.Value;
                this.EndTime.Value = DateTime.Now.AddMinutes(Convert.ToDouble(this.SumTime.Value)).ToLongTimeString();
                reader.Close();
                command.Dispose();
                connection.Close();
                connection.Dispose();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            this.httpCookie_4 = new HttpCookie("ExamDeptName");
            this.httpCookie_4 = base.Request.Cookies["ExamDeptName"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                this.intPaperID = Convert.ToInt32(base.Request["PaperID"].ToString());
                this.strLoadInfo = base.Request["LoadInfo"].ToString();
                base.Response.Expires = 0;
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.httpCookie_4.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_4.Value));
                if (!base.IsPostBack)
                {
                    this.ViewState["LoginTime"] = DateTime.Now.ToString();
                    this.ViewState["JoinExamStartTime"] = DateTime.Now.ToString();
                    this.labUserCode.Text = this.httpCookie_0.Value;
                    this.labUserName.Text = this.httpCookie_1.Value;
                    this.labDeptName.Text = this.httpCookie_4.Value;
                    if (this.labDeptName.Text.Trim().Length > 10)
                    {
                        this.labDeptName.Text = this.labDeptName.Text.Substring(0, 10) + "…";
                    }
                    string str = this.publicFun_0.GetValues("select UserPhoto from UserInfo where UserCode='" + this.httpCookie_0.Value + "'", "UserPhoto").Trim();
                    if (str != "")
                    {
                        this.ImageUser.ImageUrl = "../PublicFile/" + str;
                    }
                    this.method_1();
                    if (this.labExamTime.Text.Trim() == "0")
                    {
                        base.Response.Write("<script>alert('没有找到相关试卷参数！');</script>");
                    }
                }
                else
                {
                    this.method_0();
                    DateTime time = Convert.ToDateTime(this.ViewState["LoginTime"].ToString());
                    TimeSpan span = (TimeSpan) (DateTime.Now - time);
                    int num2 = Convert.ToInt16(span.TotalMinutes);
                    int num = Convert.ToInt16(this.ViewState["PaperSumTime"].ToString());
                    if (num2 <= num)
                    {
                        this.SumTime.Value = ((num - num2) - 1).ToString();
                    }
                    else
                    {
                        this.SumTime.Value = "1";
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

